Skip to content

FINERACT-2468: Fix datatable operations in PostgreSQL non-public schemas#5452

Open
AshharAhmadKhan wants to merge 1 commit intoapache:developfrom
AshharAhmadKhan:FINERACT-2468-fix-postgresql-datatable-schema
Open

FINERACT-2468: Fix datatable operations in PostgreSQL non-public schemas#5452
AshharAhmadKhan wants to merge 1 commit intoapache:developfrom
AshharAhmadKhan:FINERACT-2468-fix-postgresql-datatable-schema

Conversation

@AshharAhmadKhan
Copy link

Summary

Fixes datatable operations in PostgreSQL deployments using non-public schemas by replacing hardcoded 'public' schema references with current_schema.

Related Issues

Description

When using PostgreSQL with tenant-specific schemas (non-public), creating a new datatable causes:

  1. GET /datatables to return 404 with "Datatable not found"
  2. Saving data to the datatable to fail with "Datatable not found"

Root Cause: getTableIndexes() and isTablePresent() in PostgreSQLQueryService.java hardcoded 'public' schema while getTableColumns() correctly used current_schema, causing inconsistent table discovery in GenericDataServiceImpl.

Solution: Modified both methods to use current_schema instead of hardcoded 'public', ensuring all table metadata queries use the connection's current schema.

Changes Made

  • PostgreSQLQueryService.getTableIndexes(): Changed schemaname = 'public' to schemaname = current_schema
  • PostgreSQLQueryService.isTablePresent(): Changed table_schema = 'public' to table_schema = current_schema

Testing Performed

  • ✅ All unit tests pass (93/93 in fineract-core module)
  • ✅ Manual PostgreSQL verification with non-public schema confirms fix
  • ✅ Verified current_schema query finds indexes while 'public' query doesn't (reproduces original bug)

Manual Verification:

CREATE SCHEMA tenant_abc;
SET search_path TO tenant_abc;
CREATE TABLE dt_test_table (id SERIAL PRIMARY KEY, client_id INTEGER);
CREATE INDEX idx_dt_test_client ON dt_test_table(client_id);

-- Fixed query (works):
SELECT indexname FROM pg_indexes WHERE schemaname = current_schema AND tablename = 'dt_test_table';
-- Result: Returns 2 indexes ✅

-- Old buggy query (fails):
SELECT indexname FROM pg_indexes WHERE schemaname = 'public' AND tablename = 'dt_test_table';
-- Result: Returns 0 rows ❌

Impact

  • Behavior Change: None for single-tenant 'public' schema deployments (current_schema defaults to 'public')
  • Fix: Enables datatable operations in multi-tenant PostgreSQL deployments with custom schemas

Checklist

  • Write the commit message as per our guidelines
  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
  • Create/update unit or integration tests for verifying the changes made.
  • Follow our coding conventions.
  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
  • This PR must not be a "code dump". Large changes can be made in a branch, with assistance. Ask for help on the developer mailing list.

Notes

  • No API changes - internal database query fix only
  • No Swagger updates needed
  • Changes are minimal (2 SQL queries) and surgical
  • GPG-signed commit included

Use current_schema instead of hardcoded 'public' in getTableIndexes()
and isTablePresent() methods to support multi-tenant PostgreSQL
deployments where datatables reside in tenant-specific schemas.

This fixes:
- GET /datatables returning 404 for new datatables
- Datatable save operations failing with 'Datatable not found'

Root cause: Index metadata queries were looking in 'public' schema
while table columns query correctly used current_schema, causing
inconsistent behavior in GenericDataServiceImpl.

Changes:
- PostgreSQLQueryService.getTableIndexes(): Use current_schema
- PostgreSQLQueryService.isTablePresent(): Use current_schema

Testing:
- All unit tests pass (93/93 in fineract-core)
- Manual PostgreSQL verification confirms fix works correctly
@AshharAhmadKhan AshharAhmadKhan force-pushed the FINERACT-2468-fix-postgresql-datatable-schema branch from f37ed02 to 94ec550 Compare February 6, 2026 10:33
@AshharAhmadKhan
Copy link
Author

Updated to use current_schema() with explicit function call syntax for improved reliability across PostgreSQL versions.

Changes made:

  • Added parentheses to 3 occurrences of current_schema in PostgreSQLQueryService.java:
    • isTablePresent() method
    • getTableColumns() method
    • getTableIndexes() method
  • This ensures consistent schema resolution for tenant-specific PostgreSQL deployments

Regarding the CI failure:
The previous test failure (m_command table already exists error in Liquibase) appears to occur during database initialization, before datatable operations run. Since this change only affects datatable metadata queries in PostgreSQLQueryService, the failure may be unrelated to this fix. Happy to investigate further if the issue persists after the CI retry.

Thank you for your patience and review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant